#ifndef __EB_IO_H__
#define __EB_IO_H__

#ifdef __cplusplus
extern "C" {
#endif

#include <types.h>


static inline __attribute__((__always_inline__)) uint8_t read8(virt_addr_t addr)
{
	return (*((volatile uint8_t *)(addr)));
}


static inline __attribute__((__always_inline__)) uint16_t read16(virt_addr_t addr)
{
	return (*((volatile uint16_t *)(addr)));
}


static inline __attribute__((__always_inline__)) uint32_t read32(virt_addr_t addr)
{
	return (*((volatile uint32_t *)(addr)));
}


static inline __attribute__((__always_inline__)) uint64_t read64(virt_addr_t addr)
{
	return (*((volatile uint64_t *)(addr)));
}


static inline __attribute__((__always_inline__)) void write8(virt_addr_t addr, uint8_t value)
{
	*((volatile uint8_t *)(addr)) = value;
}


static inline __attribute__((__always_inline__)) void write16(virt_addr_t addr, uint16_t value)
{
	*((volatile uint16_t *)(addr)) = value;
}


static inline __attribute__((__always_inline__)) void write32(virt_addr_t addr, uint32_t value)
{
	*((volatile uint32_t *)(addr)) = value;
}


static inline __attribute__((__always_inline__)) void write64(virt_addr_t addr, uint64_t value)
{
	*((volatile uint64_t *)(addr)) = value;
}


#define __virt_to_phys(x) ((x) - CONFIG_PAGE_OFFSET + CONFIG_PHYS_OFFSET)
#define __phys_to_virt(x) ((x) - CONFIG_PHYS_OFFSET + CONFIG_PAGE_OFFSET)


static inline phys_addr_t virt_to_phys(virt_addr_t addr)
{
	return __virt_to_phys(addr);
}


static inline virt_addr_t phys_to_virt(phys_addr_t addr)
{
	return (virt_addr_t)(__phys_to_virt(addr));
}


#ifdef __cplusplus
}
#endif

#endif //! __EB_IO_H__
